package io.mybatis.example.springboot.controller;

import io.mybatis.common.core.DataResponse;
import io.mybatis.common.core.RowsResponse;

import io.mybatis.example.springboot.model.SysUserPost;
import io.mybatis.example.springboot.service.SysUserPostService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * sys_user_post - 用户与岗位关联表
 *
 * @author mkj
 */
@RestController
@RequestMapping("sysUserPosts")
public class SysUserPostController {

  @Autowired
  private SysUserPostService sysUserPostService;

  @PostMapping
  public DataResponse<SysUserPostDO> save(@RequestBody SysUserPostDO sysUserPost) {
    return DataResponse.ok(sysUserPostService.save( sysUserPost));
  }

  @GetMapping
  public RowsResponse<SysUserPostDO> findList(@RequestBody SysUserPostDO sysUserPost) {
    return RowsResponse.ok(sysUserPostService.findList( sysUserPost));
  }

  @GetMapping(value = "/{id}")
  public DataResponse<SysUserPostDO> findById(@PathVariable("id") Long id) {
    return DataResponse.ok(sysUserPostService.findById(id));
  }

  @PutMapping(value = "/{id}")
  public DataResponse<SysUserPostDO> update(@PathVariable("id") Long id, @RequestBody SysUserPostDO sysUserPost) {
    sysUserPost.setId(id);
    return DataResponse.ok(sysUserPostService.update( sysUserPost));
  }

  @DeleteMapping(value = "/{id}")
  public DataResponse<Boolean> deleteById(@PathVariable("id") Long id) {
    return DataResponse.ok(sysUserPostService.deleteById(id) == 1);
  }

}
